package org.dtc.countdown.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class CountDownProject implements EntryPoint {

	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final CountDownAsync countDownService = GWT
			.create(CountDown.class);

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		final Label time = new Label();
		
		countDownService.countDownServer(
				new AsyncCallback<Long>() {
					public void onFailure(Throwable caught) {
						time.setText("FAILURE");
					}

					public void onSuccess(Long result) {
				        time.setText(result.toString());
					}
				});
		RootPanel.get("time").add(time);
	
		final Timer countdownTimer = new Timer() {
		    public void run() {
		    	if(!time.getText().equals("")) {
		    	Long test = Long.valueOf(time.getText()) - 1;
		    	time.setText(test.toString());
		    	}
		    }
		};
		
		countdownTimer.scheduleRepeating(100);
	}
}
